package com.smartcruise.base;

import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;

/**
 * Created by FengChaoQun
 * on 2018/3/20 0020
 */

public class RefreshSimpleImp implements RefreshContract.RefreshInterface {

    private SmartRefreshLayout refreshLayout;

    public RefreshSimpleImp(SmartRefreshLayout refreshLayout) {
        this.refreshLayout = refreshLayout;
    }

    /**
     * description:自动刷新
     */
    @Override
    public void autoRefresh() {
        refreshLayout.autoRefresh(300);
    }

    /**
     * description:自动加载更多
     */
    @Override
    public void autoLoadMore() {
        refreshLayout.autoLoadMore(300);
    }

    /**
     * description:结束刷新
     *
     * @param success
     */
    @Override
    public void finishRefresh(boolean success) {
        refreshLayout.finishRefresh(success);
    }

    /**
     * description:结束加载
     *
     * @param success
     */
    @Override
    public void finishLoadMore(boolean success) {
        refreshLayout.finishLoadMore(success);
    }

    /**
     * description:设置是否可以下拉刷新
     *
     * @param enable
     */
    @Override
    public void setEnableRefresh(boolean enable) {
        refreshLayout.setEnableRefresh(enable);
    }

    /**
     * description:设置是否可以加载更多
     *
     * @param enable
     */
    @Override
    public void setEnableLoadMore(boolean enable) {
        refreshLayout.setEnableLoadMore(enable);
    }

    /**
     * description:设置数据全部加载完成，将不能再次触发加载功能
     *
     * @param noMoreData
     */
    @Override
    public void setNoMoreData(boolean noMoreData) {
        refreshLayout.setNoMoreData(noMoreData);
    }


    /**
     * description:设置刷新回调
     *
     * @param onRefreshListener
     */
    @Override
    public void setOnRefreshListener(final RefreshContract.OnRefreshListener onRefreshListener) {
        refreshLayout.setOnRefreshListener(new com.scwang.smartrefresh.layout.listener.OnRefreshListener() {
            @Override
            public void onRefresh(RefreshLayout refreshLayout) {
                onRefreshListener.onRefresh(RefreshSimpleImp.this);
            }
        });
    }

    /**
     * description:设置加载更多回调
     *
     * @param onLoadMoreListener
     */
    @Override
    public void setOnLoadMoreListener(final RefreshContract.OnLoadMoreListener onLoadMoreListener) {
        refreshLayout.setOnLoadMoreListener(new com.scwang.smartrefresh.layout.listener.OnLoadMoreListener() {
            @Override
            public void onLoadMore(RefreshLayout refreshLayout) {
                onLoadMoreListener.onLoadMore(RefreshSimpleImp.this);
            }
        });
    }
}
